<template>
  <BasicTable @register="registerTable">
    <template #tableTitle>
      <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleCreate"> 新增</a-button>
    </template>
    <template #action="{ record }">
      <TableAction :actions="getTableAction(record)"/>
    </template>
  </BasicTable>
  <SubscribeReplyModal rowKey="id" v-bind="$attrs" @register="register" @success="reload"/>
</template>

<script lang="ts" name="weixin-mp-menu" setup>
import {BasicTable, TableAction} from '/@/components/Table';
import {useListPage} from '/@/hooks/system/useListPage'
import {subscribeReplyColumn} from './data'
import {deleteMpAutoReply, pageMpAutoReply} from './api'
import SubscribeReplyModal from './SubscribeReplyModal.vue'
import {useModal} from '/@/components/Modal';

const [register, { openModal, closeModal }] = useModal();

// 列表页面公共参数、方法
const { prefixCls, tableContext } = useListPage({
  designScope: 'weixin-mp-subscribe-reply',
  tableProps: {
    api: pageMpAutoReply,
    columns: subscribeReplyColumn,
    formConfig: {
      showResetButton: false,
      showSubmitButton: false

    },
    showTableSetting: false,
    useSearchForm: false,
    bordered: true,
    actionColumn: {
      width: 120,
    },
  }
})
const [registerTable, { getForm, reload }, { rowSelection, selectedRowKeys }] = tableContext;

const handleCreate = () => {
  openModal(true, {
    isUpdate: false,
  });
}

/**
 * 编辑
 */
 const handleEdit = (record: Recordable) => {
  const { getFieldsValue } = getForm()
  openModal(true, {
    record,
    isUpdate: true,
  });
}

/**
 * 删除事件
 */
async function handleDelete(record) {
  await deleteMpAutoReply({ id: record.id }, reload);
}

/**
 * 操作栏
 */
 function getTableAction(record) {
  return [
    {
      label: '编辑',
      onClick: handleEdit.bind(null, record),
    },
    {
      label: '删除',
      popConfirm: {
        title: '是否确认删除',
        confirm: handleDelete.bind(null, record),
      },
    }
  ]
}
</script>
